package com.atguigu.webapp.service.impl;

import com.atguigu.model.pojo.ViewAppointment;
import com.atguigu.webapp.mapper.ViewAppointmentMapper;
import com.atguigu.webapp.service.ApartmentInfoService;
import com.atguigu.webapp.service.ViewAppointmentService;
import com.atguigu.webapp.vo.apartment.ApartmentDetailVo;
import com.atguigu.webapp.vo.apartment.ApartmentItemVo;
import com.atguigu.webapp.vo.appointment.AppointmentDetailVo;
import com.atguigu.webapp.vo.appointment.AppointmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Author 梅超凡
 * @Date 2024/11/12~21:58
 * @Description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
*/
@Service
@Slf4j
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;

    @Override
    public List<AppointmentItemVo> listAppointmentItemByUserId(Long userId) {
        List<AppointmentItemVo> voList = viewAppointmentMapper.listAppointmentItemByUserId(userId);
        log.info("查询结果：{}",voList);
        return voList;
    }

    @Autowired
    private ApartmentInfoService apartmentInfoService;
    @Override
    public AppointmentDetailVo getAppointmentDetailById(Long id) {

        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);
        if (viewAppointment == null){
            log.info("查询ViewAppointment结果为空");
            return null;
        }

        ApartmentItemVo itemVo  = apartmentInfoService.selectApartmentItemVoById(viewAppointment.getApartmentId());
        AppointmentDetailVo detailVo = new AppointmentDetailVo();
        //属性对拷
        BeanUtils.copyProperties(viewAppointment,detailVo);
        //属性赋值
        detailVo.setApartmentItemVo(itemVo);
        return detailVo;
    }
}




